/*

        ABluetooth - Processing for Android Bluetooth Library

        Copyright (c) 2012 Marlon J. Manrique
        
        http://www.marlonj.com

        This library is free software; you can redistribute it and/or
        modify it under the terms of the GNU Lesser General Public
        License as published by the Free Software Foundation; either
        version 2.1 of the License, or (at your option) any later version.

        This library is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        Lesser General Public License for more details.

        You should have received a copy of the GNU Lesser General
        Public License along with this library; if not, write to the
        Free Software Foundation, Inc., 59 Temple Place, Suite 330,
        Boston, MA  02111-1307  USA

	$Id$

*/

package com.marlonj.processing.abluetooth;

import java.io.InputStream;
import java.io.OutputStream;

import android.bluetooth.BluetoothSocket;

import com.marlonj.processing.aclientserver.AConnection;

/**
 * Implementation of a connection to a Bluetooth service 
 */
class ABluetoothConnection implements AConnection { 

	/**
	 * The socket use by the bluetooth connection 
	 */
	private BluetoothSocket socket; 

	/**
	 * Create a connection using the current socket to send and 
	 * receive data 
	 * 
	 * @param socket The current socket connected to the service 
	 */
	public ABluetoothConnection(BluetoothSocket socket) {
		this.socket = socket;
	}

	/**
	 * Open the connection with the service 
	 */
	public void connect() {
		try {
			socket.connect();
		} catch(Exception e) {	
			e.printStackTrace();
		}
	}

	/**
	 * Close the connection with the service 
	 */
	public void close() {
		try {
			socket.close();
		} catch(Exception e) {	
			e.printStackTrace();
		}
	}

	/**
	 * Returns the input stream to read data
	 *
	 * @return input stream
	 */
	public InputStream getInputStream() {
		try {
			return socket.getInputStream();
		} catch(Exception e) {	
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * Returns the output stream to read data
	 *
	 * @return output stream
	 */
	public OutputStream getOutputStream() {
		try {
			return socket.getOutputStream();
		} catch(Exception e) {	
			e.printStackTrace();
		}
		return null;
	}
}
